package com.ibuonline.b2b.entity;

import java.io.Serializable;

public class CmsHomeCategory implements Serializable {

	private static final long serialVersionUID = 2001134295716035183L;

	//fields
	private java.lang.Integer id;
	private java.lang.Integer catId;
	private java.lang.Boolean hot;
	private java.lang.Integer parentId;
	private java.lang.Integer displayOrder;
	private java.lang.Integer productQty;

	//default constructor
	public CmsHomeCategory() {
	}

	//getter
	public java.lang.Integer getId() {
		return id;
	}
	public java.lang.Integer getCatId() {
		return catId;
	}
	public java.lang.Boolean isHot() {
		return hot;
	}
	public java.lang.Integer getParentId() {
		return parentId;
	}
	public java.lang.Integer getDisplayOrder() {
		return displayOrder;
	}
	public java.lang.Integer getProductQty() {
		return productQty;
	}

	//setter
	public void setId(java.lang.Integer id) {
		this.id = id;
	}
	public void setCatId(java.lang.Integer catId) {
		this.catId = catId;
	}
	public void setHot(java.lang.Boolean hot) {
		this.hot = hot;
	}
	public void setParentId(java.lang.Integer parentId) {
		this.parentId = parentId;
	}
	public void setDisplayOrder(java.lang.Integer displayOrder) {
		this.displayOrder = displayOrder;
	}
	public void setProductQty(java.lang.Integer productQty) {
		this.productQty = productQty;
	}

	//equals method
	public boolean equals(Object other) {
		if (this == other)
			return true;
		if (!(other instanceof CmsHomeCategory))
			return false;

		final CmsHomeCategory cmsHomeCategory = (CmsHomeCategory)other;
		if (!this.id.equals(cmsHomeCategory.getId()))
			return false;

		return true;
	}

	//hashCode method
	public int hashCode() {
		StringBuffer keys = new StringBuffer();
		keys.append(id).append(",");
		if (keys.length() > 0)
			keys.deleteCharAt(keys.length() - 1);
		return keys.toString().hashCode();
	}

	//toString method
	public String toString() {
		return new StringBuilder("CmsHomeCategory[")
			.append("id=").append(id).append(", ")
			.append("catId=").append(catId).append(", ")
			.append("hot=").append(hot).append(", ")
			.append("parentId=").append(parentId).append(", ")
			.append("displayOrder=").append(displayOrder).append(", ")
			.append("productQty=").append(productQty).append("]").toString();
	}

	///############
	private String name;
	private String displayName;
	private int level;
	
	public String getDisplayName() {
		if(catId != null) {
			ProdCategory prodCat = com.ibuonline.b2b.common.SysCache.getCategory(catId);
			displayName = prodCat.getDisplayName();
		} 
		return displayName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public int getLevel() {
		ProdCategory cat = com.ibuonline.b2b.common.SysCache.getCategory(catId);
		String path = cat.getPath();
		level = path.split("-").length;
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}
	
}
